package com.zero.book.utils;

import com.zero.book.message.MessageConstant;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Scanner;
@AllArgsConstructor
public class CatchEnter {

    @Getter
    private static int data = 0;

    public static boolean EnterChoice(Scanner sc, MessageConstant low, MessageConstant high) {
        int data;
        try {
            data = Integer.parseInt(sc.nextLine());
            int lowerLimit = Character.getNumericValue(low.getContent().charAt(0));
            int upperLimit = Character.getNumericValue(high.getContent().charAt(0));
            //defineScopeSelection
            if (data < lowerLimit || data > upperLimit) {
                System.out.println("输入错误，请重新尝试");
                return false;
            }
        } catch (NumberFormatException e) {
            System.out.println("输入错误，请重新尝试");
            return false;
        }
        CatchEnter.data = data;
        return true;
    }
}
